const formatPrice = (price: number, currencyId: string): string => {
  switch (currencyId) {
    case 'BRL':
      return price.toFixed(2).replace('.', ',');
    default:
      return price.toFixed(2);
  }
};

/**
 * 保留指定位数的小数(最后一位四舍五入)
 * @param num 
 * @param fixed 
 * @returns fixed 
 */
export function numberFixed(num: number, fixed: number): number {
  const p = Math.pow(10, fixed);
  let dec = Math.round(num * p);
  return dec / p;
}

/**
 * 汇率换算 正常应该拉取当日汇率,这里暂时忽略
 * @param price 
 * @param currencyId 
 * @param toCurrencyId 
 * @returns currency 
 */
export function toCurrency(price: number, currencyId: string, toCurrencyId: string): number {
  switch (`${currencyId}_${toCurrencyId}`) {
    case 'USD_USD':
      return price;
    default:
      //
      throw new Error('其他价格转换未实现!');
  }
};

export default formatPrice;
